<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
    </BasicTable>
    <UserGoodsDetailModal @register="registerUserGoodsDetailModal"></UserGoodsDetailModal>
  </div>
</template>
<script lang="ts" setup name="dataTagUserGoods">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/table';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { Api } from './data/api';
import { useModal } from '@apps/antd-admin/src/components/modal';
import { columns, searchFormSchema } from './data/data';
import { useMessage } from '@apps/antd-admin/src/hooks/web/useMessage';
import UserGoodsDetailModal from './components/UserGoodsDetailModal.vue';

const { createMessage, createConfirm } = useMessage();

const { prefixCls, tableContext, handleDelete, handleSuccess, handlePost, handleBatchDelete } = useBaseTable({
  designScope: 'dataTagUserGoods-template',
  tableProps: {
    //表格标题
    title: '会员卡列表',
    //主键字段
    rowKey: 'userGoodsId',
    //列表查询handler
    handlerName: 'appUserGoodsDataTagListHandler',
    //列表接口
    listUrl: Api.page,
    //列定义
    columns,
    //查询表单配置
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      showExportButton: true,
      exportButtonOptions: {
        code: 'ACTION_dataTagUserGoodsExport',
      },
    },
    //操作列配置
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    clickToRowSelect: true,
    rowSelection: {
      type: 'radio',
    },
  },
});

const [registerTable, { getForm, setProps, reload }, { rowSelection, hasSelectedRows, selectedRow }] = tableContext;
const [registerUserGoodsDetailModal, { openModal: openUserGoodsDetailModal }] = useModal();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '查看详情',
      onClick: handlerUserGoodsDetail.bind(null, record),
    },
  ];
}

/**
 * 下拉操作栏
 */
function getDropDownAction(record): ActionItem[] {
  return [];
}

function handlerUserGoodsDetail(record) {
  openUserGoodsDetailModal(true, {
    record,
    isUpdate: false,
  });
}
</script>
